package ua.amsoft.brelok.constant;

import ua.amsoft.brelok.R;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

public class Constants {
    
    public static final String PREF_URL_KEY = "url";
    public static final String PREF_IMEI_KEY = "imei";
    public static final String PREF_UPDATE_INTERVAL = "updates_interval";
    public static final String PREF_UPDATING_TIME_FROM = "time_from";
    public static final String PREF_UPDATING_TIME_TILL = "time_till";
    public static final String IMEI_AUTHENTIFICATION_HEADER = "IMEI-Authentication";
    public static final String IMEI_AUTHENTIFICATION_FAILED = "failed";
    public static final String IMEI_AUTHENTIFICATION_PASSED = "passed";
    public static final String FILE = "data.xml";
    
    /**
     * Returns application's version
     * 
     * @param context
     * @return
     */
    public static final String getVersion(final Context context) {
        final PackageManager pm = context.getPackageManager();
        try {
            return pm.getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (final NameNotFoundException e) {
            Log.e("Constants", e.getLocalizedMessage());
        }
        return "";
    }
    
    /**
     * Returns app signature
     * 
     * @param context
     *            - {@link Context}
     * @return {@link String} app built signature
     */
    public static final String getAppSignature(final Context context) {
        
        final String appName = context.getString(R.string.app_name);
        final String yearCreated = "2012";
        final String version = getVersion(context);
        final String createdBy = context.getString(R.string.app_created_by);
        
        final StringBuffer sb = new StringBuffer();
        sb.append(appName);
        sb.append(" ");
        sb.append(yearCreated);
        sb.append(" ");
        sb.append(version);
        sb.append(" ");
        sb.append(createdBy);
        return sb.toString();
    }
    
}
